/**
 *
 */
package susano.demo.service.company;

import java.util.List;

import susano.common.util.BeanMap;
import susano.common.util.EntityUtil;
import susano.datastore.manager.DatastoreManager;
import susano.demo.model.company.Employee;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;

/**
 *
 * @author tanaka.akira.2006
 *
 */
public class EmployeeService {

	protected DatastoreManager dm = new DatastoreManager();

	public List<BeanMap> findAll(String parent) {
		Key parentKey = KeyFactory.stringToKey(parent);

		// ROOTエンティティキー(会社のキー)の従業員を取得
		Query query = new Query(Employee.class.getSimpleName(), parentKey);
		List<Entity> emps = dm.asList(query);

		return EntityUtil.createBeanMaps(emps);
	}

	public boolean put(BeanMap employee, String parentKeyStr) {
		Entity entity = EntityUtil.createEntity(employee, parentKeyStr,
				Employee.class.getSimpleName());
		dm.put(entity);
		return dm.commit();
	}

}
